﻿using BussinessObject.ObjectTwo;
using Class_Entity.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;

namespace ProjectHK3.Object_One
{
    public partial class BranchDetail : System.Web.UI.Page
    {
        B_LoadDrop bl = new B_LoadDrop();
        B_Search bs = new B_Search();
        CC_Branches br = new CC_Branches();
        B_Update mn = new B_Update();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load();
            }
        }
        public void load()
        {
            DropDownList1.DataSource = bl.Company();
            DropDownList1.DataTextField = "COMPANY_NAME";
            DropDownList1.DataValueField = "COMPANY_ID";
            DropDownList1.DataBind();

            DropDownList2.DataSource = bl.city();
            DropDownList2.DataTextField = "CITY_NAME";
            DropDownList2.DataValueField = "CITY_ID";
            DropDownList2.DataBind();

            br = bs.loadBran(int.Parse(Session["Bran"].ToString()));

            TextBox1.Text = br.BRANCH_CODE;
            TextBox2.Text = br.BRANCH_NAME;
            TextBox3.Text = br.ADDRESS;
            TextBox4.Text = br.BRANCH_PHONE;
            TextBox5.Text = br.DESCRIPTION;

            DropDownList1.SelectedValue = br.COMPANY_ID.ToString();
            DropDownList2.SelectedValue = br.CITY_ID.ToString();

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            br.BRANCH_ID = int.Parse(Session["Bran"].ToString());
            br.BRANCH_NAME = TextBox2.Text;
            br.BRANCH_CODE = TextBox1.Text;
            br.COMPANY_ID =int.Parse( DropDownList1.SelectedValue.ToString());
            br.ADDRESS =TextBox3.Text;
            br.BRANCH_PHONE = TextBox4.Text;
            br.DESCRIPTION = TextBox5.Text;
            br.CITY_ID = int.Parse(DropDownList2.SelectedValue.ToString());
            if (mn.updateBranch(br) == true)
            {
                Alert.Show("Update successful");
            }
            else
            {
                Alert.Show("Update fail !!!");
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {

        }
    }
}